package books.ThinkingInJava.src.Chapter14;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class DynamicProxyHandler implements InvocationHandler {
    Object obj = new Object();

    public DynamicProxyHandler(Object ob) {
        obj = ob;
    }

    public static void main(String[] args) throws Throwable {
        Method method = Class.forName("Chapter14.Gum").getMethods()[0];
        DynamicProxyHandler dph = new DynamicProxyHandler(new Gum());
        dph.invoke(null, method, new Object[]{"In invoker!"});
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return method.invoke(obj, args);
    }
}
